package com.ruoyi.scheme.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.scheme.dto.EcologicalRepairSchemeDTO;
import com.ruoyi.scheme.dto.ValidationGroups;
import com.ruoyi.scheme.pojo.EcologicalRepairScheme;
import com.ruoyi.scheme.service.EcologicalRepairSchemeService;
import com.ruoyi.scheme.vo.EcologicalRepairSchemeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.sf.jsqlparser.statement.update.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/ers/scheme")
@Api(tags = "生态修复方案相关接口")
public class EcologicalRepairSchemeController {

    @Autowired
    private EcologicalRepairSchemeService ecologicalRepairSchemeService;

    //创建生态修复方案接口
    @PostMapping("/create")
    @ApiOperation("创建生态修复方案接口")
    public R<String> create(@Validated(ValidationGroups.Create.class)
                            @RequestBody EcologicalRepairSchemeDTO ecologicalRepairSchemeDTO) {
        ecologicalRepairSchemeService.create(ecologicalRepairSchemeDTO);
        return R.ok("生态修复方案创建成功");
    }

    //修改生态修复方案接口
    @PutMapping("/update")
    @ApiOperation("修改生态修复方案接口")
    public R<String> update(@RequestBody  @Validated(ValidationGroups.Update.class)
                                EcologicalRepairSchemeDTO ecologicalRepairSchemeDTO) {
        ecologicalRepairSchemeService.update(ecologicalRepairSchemeDTO);
        return R.ok("生态修复方案修改成功");
    }

    //查询生态修复方案接口
    @GetMapping("/search")
    @ApiOperation("查询生态修复方案接口")
    public R<List<EcologicalRepairSchemeVO>> search(@RequestParam(required = false) Long schemeId,
                                                    @RequestParam(required = false) Integer patchId) {
        List<EcologicalRepairSchemeVO> list=ecologicalRepairSchemeService.search(schemeId,patchId);
        return R.ok(list);
    }

    //删除生态修复方案接口
    @DeleteMapping("/delete")
    @ApiOperation("删除生态修复方案接口")
    public R<String> delete(@RequestParam @NotNull(message = "生态修复方案ID不能为空") Long schemeId) {
        ecologicalRepairSchemeService.delete(schemeId);
        return R.ok("生态修复方案删除成功");
    }

}
